package com.chao.wind3j.base.config.swaggerConfig;

import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

public class SwaggerConfig {
  /**
   * restApi基本配置
   * @return
   */
  @Bean
  public Docket createRestApi() {
    ParameterBuilder tokenPar = new ParameterBuilder();
    List<Parameter> pars = new ArrayList<Parameter>();
    tokenPar.name("x-access-token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(true).build();
    pars.add(tokenPar.build());
    return new Docket(DocumentationType.SWAGGER_2)
      .pathMapping("/")
      .select()
      .apis(RequestHandlerSelectors.basePackage("com.chao.wind3j.controller"))
      .paths(PathSelectors.any())
      .paths(PathSelectors.regex("(?!/error.*).*"))
      .build().globalOperationParameters(pars)
            .apiInfo(new ApiInfoBuilder()
                    .title("Wind3J Swagger")
                    .version("9.0")
                    .license("The Apache License")
                    .licenseUrl("http://www.baidu.com")
                    .build());
  }
}
